﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using Model;


namespace DAL
{
    public class level
    {
        public static string connectionString = ConfigurationManager.ConnectionStrings["projectbConnection"].ToString();
        public List<Model.Level> select()
        {
            DataSet ds = new DataSet();
            List<Model.Level> level =new List<Model.Level>();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();
                    SqlCommand comm = new SqlCommand("select LevelName, LevelId from Level",conn);
                    SqlDataAdapter da = new SqlDataAdapter(comm);
                    da.Fill(ds,"Level");
                    //return ds;
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.Level c = new Model.Level { 
                            LevelName=row[0].ToString(),
                            LevelId=Convert.ToInt32(row[1])
                        };
                        level.Add(c);

                   }
                    return level;
                }
                catch (SqlException e)
                {
                    throw new Exception(e.Message);
                }
                
            }

        }
    }
}

        

   

